<?php
/**
 * Created by .
 * User: luogan
 * Date: 2022/1/17
 */

namespace app\admin\controller\v1;


use app\admin\service\DeptService;
use app\admin\validate\DeptValidate;
use app\interfaces\AdminInterface;
use hg\apidoc\annotation as Apidoc;

/**
 * @Apidoc\Title("部门管理")
 * @Apidoc\Group("system")
 * @Apidoc\Sort(4)
 */
class Dept extends Base implements AdminInterface
{

    protected $service;

    protected $validate;

    public function __construct()
    {
        $this->service = new DeptService();
        $this->validate = new DeptValidate();
    }

    /**
     * @Apidoc\Title("部门列表")
     * @Apidoc\Desc("部门列表")
     * @Apidoc\Method("POST")
     * @Apidoc\Author("luogan")
     * @Apidoc\Url("v1/dept/list")
     * @Apidoc\Tag("部门")
     * @Apidoc\Returned(type="array",ref="app\model\DeptModel\getDeptTreeList",default="部门列表")
     */
    public function list()
    {
        $data = $this->checkParam(__FUNCTION__);
        $result = $this->service->getList($data);
        return success('操作成功',$result);
    }

    /**
     * @Apidoc\Title("部门详情")
     * @Apidoc\Desc("部门详情")
     * @Apidoc\Method("POST")
     * @Apidoc\Author("luogan")
     * @Apidoc\Url("v1/dept/info")
     * @Apidoc\Tag("部门")
     * @Apidoc\Returned(ref="app\model\DeptModel\getDept")
     */
    public function info()
    {
        $data = $this->checkParam(__FUNCTION__);
        $result = $this->service->getInfo($data);
        return success('操作成功',$result);
    }

    /**
     * @Apidoc\Title("部门新增")
     * @Apidoc\Desc("部门新增")
     * @Apidoc\Method("POST")
     * @Apidoc\Author("luogan")
     * @Apidoc\Url("v1/dept/add")
     * @Apidoc\Tag("部门")
     * @Apidoc\Param("name",type="int",require=true,default="1",desc="部门名称")
     * @Apidoc\Param("description",type="int",require=true,default="1",desc="描述")
     * @Apidoc\Param("sort",type="int",require=true,default="1",desc="排序")
     * @Apidoc\Param("status",type="int",require=true,default="1",desc="状态 0:开启  1禁用")
     * @Apidoc\Param("parent_id",type="int",require=true,default="1",desc="父级id")
     * @Apidoc\Param("mobile",type="int",require=true,default="1",desc="手机号")
     * @Apidoc\Param("email",type="int",require=true,default="1",desc="邮箱")
     * @Apidoc\Param("duty",type="int",require=true,default="1",desc="责任人")
     * @Apidoc\Returned(ref="app\model\DeptModel\getDept")
     */
    public function add()
    {
        $data = $this->checkParam(__FUNCTION__);
        $result = $this->service->create($data);
        return success('操作成功',$result);
    }

    /**
     * @Apidoc\Title("部门更新")
     * @Apidoc\Desc("部门更新")
     * @Apidoc\Method("POST")
     * @Apidoc\Author("luogan")
     * @Apidoc\Url("v1/dept/edit")
     * @Apidoc\Tag("部门")
     * @Apidoc\Param("id",type="int",require=true,default="1",desc="部门id")
     * @Apidoc\Param("name",type="int",require=true,default="1",desc="部门名称")
     * @Apidoc\Param("description",type="int",require=true,default="1",desc="描述")
     * @Apidoc\Param("sort",type="int",require=true,default="1",desc="排序")
     * @Apidoc\Param("status",type="int",require=true,default="1",desc="状态 0:开启  1禁用")
     * @Apidoc\Param("parent_id",type="int",require=true,default="1",desc="父级id")
     * @Apidoc\Param("mobile",type="int",require=true,default="1",desc="手机号")
     * @Apidoc\Param("email",type="int",require=true,default="1",desc="邮箱")
     * @Apidoc\Param("duty",type="int",require=true,default="1",desc="责任人")
     */
    public function edit()
    {
        $data = $this->checkParam(__FUNCTION__);
        $result = $this->service->update($data);
        return success('操作成功',$result);
    }

    /**
     * @Apidoc\Title("部门删除")
     * @Apidoc\Desc("部门删除")
     * @Apidoc\Method("POST")
     * @Apidoc\Author("luogan")
     * @Apidoc\Url("v1/dept/del")
     * @Apidoc\Tag("部门")
     */
    public function del()
    {
        $data = $this->checkParam(__FUNCTION__);
        $result = $this->service->delete($data);
        return success('操作成功',$result);
    }
}
